import { defineStore } from "pinia";
const getTempData = () => ({
  goods_id: null,
  code: "",
  name: "",
  cate_id: null,
  specification: "",
  unit: "",
  in_price: 0.0,
  out_price: 0.0,
  safety_stock: 0.0,
  supplier_id: null,
  note: "",
  status: 1,
  //   purchaseCount: 0,
});

export const GoodsTempStore = defineStore("goodsTemp", {
  state: () => ({
    // 存储用户上次未保存的表单数据
    tempFormData: getTempData(),
  }),

  actions: {
    saveTempData(data) {
      this.tempFormData = JSON.parse(JSON.stringify(data));
    },
    clearTempData() {
      this.tempFormData = getTempData();
    },
  },

  persist: {
    key: "goods-form-temp-data",
    storage: localStorage,
  },
});
